//
//  ThreeControllerViewController.swift
//  one
//
//  Created by huangfeng on 2018/5/3.
//  Copyright © 2018年 huangfeng. All rights reserved.
//

import UIKit

class ThreeControllerViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let onebtn = UIButton(frame: CGRect(x: 20, y: 30, width: 100, height: 30))
        onebtn.addTarget(self, action: #selector(clickMe(btn:)), for: .touchUpInside)
        onebtn.setTitle("返回", for: .normal)
        onebtn.setTitleColor(#colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1), for: .normal)
        onebtn.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        onebtn.layer.cornerRadius = 5
        onebtn.layer.shadowOffset = CGSize(width: 100, height: 20)
        onebtn.layer.shadowColor = UIColor.black.cgColor
        view.addSubview(onebtn)
        
        let url = URL(string: "http://www.baidu.com")
        URLSession.shared.dataTask(with: url!) { (data, _, error) in
            guard let data = data else{
                print("网络请求失败 \(String(describing: error))")
                return
            }
            let html = String(data: data, encoding: .utf8)
            print(html ?? "")
        }.resume()
        
        let three = TwoObject(name: "huang", age: 108)
        // age = 108 的时候 便利构造函数判断age > 100 返回了nil  three == nil
        print(three ?? "nil")
        
        let textfiled = UITextField(frame: CGRect(x: 50, y: 80, width: 120, height: 30), placeholder: "0")
        view.addSubview(textfiled)
        
        let btn = UIButton(title: "huagnfeng", color: UIColor.blue)
        btn.frame = CGRect(x: 50, y: 200, width: 300, height: 30)
        view.addSubview(btn)
        
        // Do any additional setup after loading the view.
    }
    
    
    @objc func clickMe(btn:UIButton) {
        self.dismiss(animated: true, completion: nil)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
